<?php
declare(strict_types=1);

namespace Api\Cola;

use Mine\Mine;
use Mine\MineRequest;
use Mine\MineResponse;
use Mine\Traits\ControllerTrait;

/**
 * 可乐账本Api基类
 * Class ColaBaseApi.
 */
abstract class ColaBaseController
{
    use ControllerTrait;

    public function __construct(
        readonly protected Mine         $mine,
        readonly protected MineRequest  $request,
        readonly protected MineResponse $response
    )
    {
    }

    public function getResponse(): MineResponse
    {
        return $this->response;
    }

    public function getRequest(): MineRequest
    {
        return $this->request;
    }

    /**
     * 获取分页数据
     * @return array
     */
    public function getPageSize(): array
    {
        // 获取请求中的 page 和 size 参数，设置默认值
        $page = (int)$this->request->input('page', 1);
        $size = (int)$this->request->input('size', 20);

        // 计算 offset
        $new_page = ($page - 1) * $size;

        return [$new_page, $size, $page];
    }

}
